package com.bytecodezz.app.base.extend.ui

import android.view.View
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.delay


fun View.onClick(interval: Long = 800, action: suspend (View) -> Unit) {
    // 启动一个 actor
    val eventActor = GlobalScope.actor<View>(Dispatchers.Main) {
        for (event in channel) {
            action(event)
            delay(interval)
        }
    }
    // 设置一个监听器来启用 actor
    setOnClickListener {
        eventActor.offer(it)
    }
}